const CryptoJS = require('crypto-js');

var _utils_constant__WEBPACK_IMPORTED_MODULE_1__ = {
    "DZ": [
        "0",
        "1",
        "2",
        "3",
        "4"
    ],
    "FB": [
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "a",
        "b",
        "c",
        "d",
        "e",
        "f",
        "g"
    ],
    "GU": "appsapi2",
    "JQ": [
        "O",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "o",
        "p",
        "q",
        "r",
        "s",
        "t"
    ],
    "NZ": [
        "5",
        "6",
        "7",
        "8",
        "9"
    ],
    "eR": [
        "H",
        "I",
        "J",
        "K",
        "L",
        "M",
        "N",
        "h",
        "i",
        "j",
        "k",
        "l",
        "m",
        "n"
    ],
    "o": [
        "U",
        "V",
        "W",
        "X",
        "Y",
        "Z",
        "u",
        "v",
        "w",
        "x",
        "y",
        "z"
    ]
}

var encrypt = function(t, e, n) {
    void 0 === t && (t = ""),
    void 0 === n && (n = !1);
    var r = n ? t : t + _utils_constant__WEBPACK_IMPORTED_MODULE_1__.GU
        , o = CryptoJS.enc.Utf8.parse(r)
        , i = CryptoJS.enc.Utf8.parse(e);
    return CryptoJS.AES.encrypt(i, o, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.ZeroPadding
    }).toString()
}

var encryptMap = function(word, params) {
    void 0 === word && (word = ""),
    void 0 === params && (params = {});
    var key = params.key || getNewKey(params.as);
    switch (params.method) {
        case "aes-ecb":
            return encrypt(key, word, !0);
        case "des-ecb":
            return encryptDes(key, word);
        case "custom":
            try {
                var callback = "cb_" + getRandom(8);
                return eval("window.".concat(callback, " = ").concat(params.custom)),
                    window[callback](word)
            } catch (t) {
                return console.error("sytnx Error"),
                    encrypt(key, word, !0)
            }
        default:
            return encrypt(key, word, !0)
    }
}

var getNewKey = function(t) {
    void 0 === t && (t = "");
    var e = t + _utils_constant__WEBPACK_IMPORTED_MODULE_1__.GU
        , n = ""
        , r = t.substr(t.length - 1, 1) || "";
    switch (!0) {
        case _utils_constant__WEBPACK_IMPORTED_MODULE_1__.FB.includes(r):
            n = CryptoJS.MD5(e).toString();
            break;
        case _utils_constant__WEBPACK_IMPORTED_MODULE_1__.eR.includes(r):
            n = CryptoJS.SHA1(e).toString();
            break;
        case _utils_constant__WEBPACK_IMPORTED_MODULE_1__.JQ.includes(r):
            n = CryptoJS.SHA256(e).toString();
            break;
        case _utils_constant__WEBPACK_IMPORTED_MODULE_1__.o.includes(r):
            n = CryptoJS.SHA512(e).toString();
            break;
        case _utils_constant__WEBPACK_IMPORTED_MODULE_1__.DZ.includes(r):
            n = CryptoJS.SHA3(e, {
                outputLength: 256
            }).toString();
            break;
        case _utils_constant__WEBPACK_IMPORTED_MODULE_1__.NZ.includes(r):
            n = CryptoJS.SHA3(e, {
                outputLength: 512
            }).toString();
            break;
        default:
            n = e
    }
    return n.slice(0, 16)
}

function fillZero(t=1) {
    let e = "";
    for (var r = 0; r < t; r++)
        e += "0";
    return e
}

sha1Pow = (t="") => CryptoJS.SHA1(t).toString()

function pow(t, e) {
    const r = fillZero(e.count)
        , i = Date.now();
    let n, o = 0, s = "0";
    for (; s !== r && !this.flag; )
        s = this[e.version](e.originStr[t] + o).substring(0, e.count),
            o++;

    return n = Date.now() - i,
        {
            t: n,
            an: o - 1
        }
}

function getPow(spin, m, c) {
    var e;
    switch (m) {
        case "s":
        default:
            e = "sha1Pow";
            break;
        case "m":
            e = "md5Pow"
    }
    var cfg = {
        "originStr": {
            "spin-0": spin
        },
        "list": [
            "spin-0"
        ],
        "version": e,
        "count": parseInt(c) || 2
    }
    return pow('spin-0', cfg)
}

function getFS(ac_c, backstr, as, styleSpin, styleM, styleC) {
    var now = new Date().getTime();
    var rzData = {
        "common": {
            "cl": [],
            "mv": [],
            "sc": [],
            "kb": [],
            "sb": [],
            "sd": [],
            "sm": [],
            "cr": {
                "screenTop": 0,
                "screenLeft": 0,
                "clientWidth": 320,
                "clientHeight": 273,
                "screenWidth": 2195,
                "screenHeight": 1235,
                "availWidth": 2195,
                "availHeight": 1187,
                "outerWidth": 2195,
                "outerHeight": 1187,
                "scrollWidth": 320,
                "scrollHeight": 320
            },
            "simu": 0
        },
        "backstr": backstr,
        "captchalist": {
            "spin-0": {
                "cr": {
                    "left": -10,
                    "top": 30,
                    "width": 290,
                    "height": 239
                },
                "back": {
                    "left": 59,
                    "top": 61,
                    "width": 152,
                    "height": 152
                },
                "mv": [
                    {
                        "t": now,
                        "fx": 4,
                        "fy": 260
                    },
                    {
                        "t": now+50,
                        "fx": 6,
                        "fy": 260
                    },
                    {
                        "t": now+88,
                        "fx": 27,
                        "fy": 236
                    },
                    {
                        "t": now+124,
                        "fx": 23,
                        "fy": 237
                    },
                    {
                        "t": now+160,
                        "fx": 22,
                        "fy": 239
                    }
                ],
                "ac_c": ac_c,
                "p": getPow(styleSpin, styleM, styleC)
            }
        }
    }
    var fs = encryptMap(JSON.stringify(rzData), {
        "method": "aes-ecb",
        "key": "",
        "custom": "",
        "as": as
    });
    fs = encryptMap(JSON.stringify({
        common_en: fs,
        backstr: backstr
    }), {
        // key: "f858bc90fa4cbc0d", // 可能动态变化
        as: as,
        method: "aes-ecb"
    })
    return fs
}

// console.log(getFS(0.07, '8312-PjbKsLqOZ/JNMmIwnseRNMbQDreaH3nBAS9ohl3ihJYGLGAJK/ngaeejf03ynD6y8ndsXHlmh7TphOf5e+qjGRO5Qqb0I7F2pkC5K0J1Esi5XNa93XOB2tXK993gGd5N3M8sJ/qWSRWNss5HDKSbym7z4xmsHjheBh3r96ZtawtC5iy6QlbE9ppAzD0gJtddL+wvkX92xuB21+Om0gvR8CiEYB3PKq/RRRYJIPiLwjjMkC+q/NCB7gMHCd9srtsLzbpJGfItBY9UoTsZuG0aeD72GtKrTFoTewSh1FEV52zNfpkILx6r5MqkiWUxvgQgC5T1ZB1my/TZRSEuUbvrnFaFc5vQaHVfmZbJLBp2XEhqjyGkJuKwnjB4QCFUU90spAADFfwMoHjm6xDLI+Zqt4ed2SfBghylNqwQ4YJoylzlJveGO5e5EQO+pklJLmgREQEDnHOdk/iYPt8rKFyriSLdQUlJpJWZSSSQ1T9sC2wWYI6v4QR4Cp2scWcz15Vxy0+RbmAYQNfPKrJE6Eqitgpgb4D3r0BXjLxWN1KTAgKuPzukt705w+VYBljBFdQyYmeVJSAeUf59nFMWdAXta9e5ZKVNARMDCuey2tf5nmaXSrKLSQQ29TEJoQWwLw/6EoZFwVyLTKR/sdGSPIafxN64lh4HfwtYx3Us63fpeDnZQJuefdLte/aTo31qxKk1tffrm9IA2DilhSrU5RCq3Q==', '3fdd9402'));

const args = process.argv.slice(2);
if (args.length === 0) {
    return
}
eval(args[0]);
